<?php
    //验证手机位数
    if( ! preg_match('/\d{11}$/',$_POST['phone'] ))
        {
         skip('student_in.php','glyphicon-remove-sign','请输入正确的手机号');
        }


    //学号不得重复
     $query = "select * from student where sid='{$_POST['sid']}' ";
     $result = execute($link,$query);
      if(mysqli_num_rows($result)){
          skip('student_in.php','glyphicon-remove-sign','这个学号已被注册');
      }


      //联系方式不得重复
      $query = "select * from student where phone='{$_POST['phone']}' ";
      $result = execute($link,$query);
       if(mysqli_num_rows($result)){
            skip('student_in.php','glyphicon-remove-sign','这个手机号已被注册');
       }


       //验证学号长度
      if(mb_strlen($_POST['sid'])>13 || mb_strlen($_POST['sid'])<11){
        skip('student_in.php','glyphicon-remove-sign','学号长度不正确');
      }

       //判断宿舍是否存在
      $query="select * from sushe where ldh='{$_POST['ldh']}' and ssh={$_POST['ssh']} ";
      $result=execute($link,$query);
      if(!mysqli_num_rows($result)){
        skip('student_in.php','glyphicon-remove-sign','暂未开放此宿舍');
      }



     //判断寝室是否满人  ？？？？？

    $query="select * from student where ldh='{$_POST['ldh']}' and ssh={$_POST['ssh']} ";
    $result=execute($link,$query);
    echo $_POST['ldh'] .'<br>';
    echo mysqli_num_rows($result);

    $num=4;
    if( mysqli_num_rows($result) >= $num ){
         skip('student_in.php','glyphicon-remove-sign','此宿舍已经满人，请换宿舍');
    }






?>